//
//  InspectionContentCell.m
//  PropertyMananger
//
//  Created by Mansion on 17/1/21.
//  Copyright © 2017年 BH. All rights reserved.
//

#import "InspectionContentCell.h"

@implementation InspectionContentCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *cellID = @"InspectionContentCellID";
    InspectionContentCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if(cell == nil) {
        cell = [[InspectionContentCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    //选中cell的颜色 -无色
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
    
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.titleLabel = [[UILabel alloc]init];
        [self.contentView addSubview:self.titleLabel];
        self.titleLabel.textColor = BHColor(102, 102, 102);
        
        self.titleLabel.font = BHFont(15);
        self.titleLabel.textAlignment = NSTextAlignmentLeft;
        self.titleLabel.text = @"巡检内容";
        
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(self).with.offset(15);
            make.top.equalTo(self).with.offset(10);
            make.size.mas_equalTo(CGSizeMake(100, 25));
        }];
        
        self.contentLabel  = [[UILabel alloc]init];
        [self.contentView addSubview:self.contentLabel];
        self.contentLabel.font = BHFont(15);
        
        self.contentLabel.textAlignment = NSTextAlignmentLeft;
        self.contentLabel.textColor = BHColor(51, 51, 51);
        self.contentLabel.numberOfLines = 0;
        //self.contentLabel.backgroundColor = BHRandColor;
        
        [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(self.titleLabel).with.offset(0);
            make.top.equalTo(self.titleLabel.mas_bottom).with.offset(5);
            make.right.mas_equalTo(self.contentView).with.offset(-15);
        }];
    }
    return self;
}
+ (CGFloat)MyInspectContentHeightWiht:(MyInspectModel *)model{
    
    //展开后得高度(计算出文本内容的高度+固定控件的高度)
    NSDictionary *attribute = @{NSFontAttributeName: [UIFont systemFontOfSize:15]};
    NSStringDrawingOptions option = (NSStringDrawingOptions)(NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading);
    CGSize size = [model.InspectContent boundingRectWithSize:CGSizeMake(BHscreenW - 20, MAXFLOAT) options:option attributes:attribute context:nil].size;
    
    if(size.height < 30){
        size.height = 30;
    }
    return size.height + 50;
    
}
- (void)setModel:(MyInspectModel *)model{

    _model = model;
    
    self.contentLabel.text = model.InspectContent;

}
@end
